/*
* Copyright 2006-2007 Javector Software LLC
*
* Licensed under the GNU General Public License, Version 2 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.gnu.org/copyleft/gpl.html
*
* THE SOURCE CODE AND ACCOMPANYING FILES ARE PROVIDED WITHOUT ANY WARRANTY,
* WRITTEN OR IMPLIED.
*
* The copyright holder provides this software under other licenses for those
* wishing to include it with products or systems not licensed under the GPL.
* Contact licenses@javector.com for more information.
*/
package com.javector.soaj;

/**
 * Wrapper class for unchecked exceptions thrown within the SOAJ Framework. 
 * Provides some useful constructors that are not available with
 * java.lang.RuntimeException.  Also identifies the source of the exception as 
 * local to the SOAJ Framework.  All unchecked exceptions generated by SOAJ
 * should derive from this class.
 * 
 * @author Mark Hansen (mark@javector.com)
 */
public class SoajRuntimeException extends RuntimeException {

  private static final String NL = System.getProperty("line.separator");
  
  public SoajRuntimeException() { super(); }
  public SoajRuntimeException(String s) { super(s); }
  public SoajRuntimeException(Throwable t) { super(t); }
  public SoajRuntimeException(String s, Throwable t) { super(s,t); }
  
  public SoajRuntimeException(String[] reasons) {
    super(flatten(reasons));
  }
  
  private static synchronized String flatten(String[] reasons) {
    
    String reason = "";
    for (int i=0; i<reasons.length; i++) {
      if (reason.length() > 0) { reason += NL; }
      if ( reasons[i] != null && reasons[i].length() > 0 ) {
      reason += reasons[i];
      }
    }
    return reason;
    
  }
  
  public SoajRuntimeException(String[] reasons, Throwable cause) {
    this(flatten(reasons), cause);
  }

}